package com.redeye.bastinger.activities;


import android.annotation.SuppressLint;
//import android.app.ActionBar;
import android.app.AlertDialog;
//import android.content.DialogInterface;
import android.media.AudioManager;
//import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
//import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.view.MenuItem;

import com.redeye.bastinger.R;

/**
 * A {@link PreferenceActivity} that presents a set of application settings. On
 * handset devices, settings are presented as a single list. On tablets,
 * settings are split by category, with category headers shown to the left of
 * the list of settings.
 * <p>
 * See <a href="http://developer.android.com/design/patterns/settings.html">
 * Android Design: Settings</a> for design guidelines and the <a
 * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
 * API Guide</a> for more information on developing a Settings UI.
 */
public class HelpActivity extends PreferenceActivity {

	private AlertDialog.Builder dialog;

	@SuppressLint({"NewApi", "SuspiciousIndentation"})
	@SuppressWarnings("deprecation")
	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.help_menu);
		//todo
		/*ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);*/

		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		
		/* Initialize Dialog */
	    dialog = new AlertDialog.Builder(this);
	    dialog.setCancelable(true);
	    dialog.setNeutralButton(R.string.action_backtomain, (dialog, which) -> dialog.dismiss());
		
	    /* Register on Click Callbacks */
		prefButton(
				"pref_help_scoring",
				R.string.pref_help_scoring_title,
				R.string.pref_help_scoring_message
		);
		prefButton(
				"pref_help_levels",
				R.string.pref_help_levels_title,
				R.string.pref_help_levels_message
		);
		prefButton(
				"pref_help_vibration",
				R.string.pref_help_vibration_title,
				R.string.pref_help_vibration_message
		);
		prefButton(
				"pref_help_apm",
				R.string.pref_help_apm_title,
				R.string.pref_help_apm_message
		);
		prefButton(
				"pref_help_fps",
				R.string.pref_help_fps_title,
				R.string.pref_help_fps_message
		);
		prefButton(
				"pref_help_randomizer",
				R.string.pref_help_randomizer_title,
				R.string.pref_help_randomizer_message
		);
		prefButton(
				"pref_help_resumability",
				R.string.pref_help_resumability_title,
				R.string.pref_help_resumability_message
		);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		finish();
		return true;
	}
	private void prefButton(String key, Integer title, Integer message) {
		Preference pref = findPreference(key);
		pref.setOnPreferenceClickListener(preference -> {
			dialog.setTitle(title);
			dialog.setMessage(message);
			dialog.show();
			return true;
		});
	}
}
